<?php
// +----------------------------------------------------------------------
// | ZanPianCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.zanpian.com All rights reserved.
// +----------------------------------------------------------------------
// | BBS:  <http://www.feifeicms.cc>
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
use think\Cache;
class Theme extends Model{
    // 定义时间戳字段名
    protected $createTime = '';
    protected $updateTime = '';
	// 自动完成
	protected $auto = ['theme_addtime','theme_content'];
	protected $insert = [];
	protected $update = [];		
	protected function setThemeAddtimeAttr($value,$data){
		if (!empty($data['theme_checktime']) || empty($value)) {
			return time();
		}else{
			return strtotime($value);
		}
	}
	protected function setThemeContentAttr($value){
	    if(!empty($value)){
	       return zanpian_content_down_images(trim($value),'Theme');
	    }else{
	       return ""; 	 
	    } 
	}
	protected function setThemeUidAttr($value){
		if($value){
			return $value;
		}else{
			return '';
		}
	}	
	//事件注册
    protected static function init(){
		//写入后置事件
		Theme::afterWrite(function ($Theme){

		});		
		//删除后置操作
        Theme::afterDelete(function ($Theme) {
			zanpian_del_img_file($Theme['theme_content']);
       });	
    }		
    public function vod(){
        return $this->hasOne('vod','vod_id','theme_vid');
    }
    public function user(){
        return $this->hasOne('user','user_id','theme_uid');
    }	
}